<?php

namespace app\admin\model\study;

use think\Model;


class Author extends Model
{

    

    // 表名
    protected $table = 'study';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'is_good_text',
        'is_good_text',
        'state_text',
        'is_week_text'
    ];

    
    public function getIsGoodList()
    {
        return ['0' => __('Is_good 0'), '1' => __('Is_good 1')];
    }

    public function getStateList()
    {
        return ['0' => __('State 0'), '1' => __('State 1')];
    }

    public function getIsWeekList()
    {
        return ['0' => __('Is_week 0'), '1' => __('Is_week 1')];
    }


    public function getTimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['time']) ? $data['time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }


    public function getIsGoodTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_good']) ? $data['is_good'] : '');
        $list = $this->getIsGoodList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['state']) ? $data['state'] : '');
        $list = $this->getStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getIsWeekTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['is_week']) ? $data['is_week'] : '');
        $list = $this->getIsWeekList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function studyclass()
    {
        return $this->belongsTo('app\admin\model\StudyClass', 'class_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }


    public function studyauthor()
    {
        return $this->belongsTo('app\admin\model\StudyAuthor', 'author_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
